package com.tong.lib.greendao;

import android.database.sqlite.SQLiteDatabase;

import com.tong.lib.utils.AppContextUtil;

import hjt.com.componentbase.db.DaoMaster;
import hjt.com.componentbase.db.DaoSession;

/**
 * Created by hjt on 2019/5/24.
 */

public class DaoManager {

    private static DaoSession daoSession;

    private DaoManager() {

    }

    /**
     * 在application中先初始化下，可以减少第一次调用初始化的时间
     *
     * @return
     */
    public static DaoSession getInstance() {
        if (daoSession == null) {
            synchronized (DaoManager.class) {
                if (daoSession == null) {
                    MyDaoMaster helper = new MyDaoMaster(AppContextUtil.getContext(), "greendao.db");
                    SQLiteDatabase db = helper.getWritableDatabase();
                    DaoMaster daoMaster = new DaoMaster(db);
                    daoSession = daoMaster.newSession();
                }
            }
        }
        return daoSession;
    }


}
